package com.tf.six.controller;

import com.tf.six.service.HotProductStatisticService;
import com.tf.six.service.TransactionStatisticService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Tag(name = "数据统计", description = "数据统计相关接口")
@RestController
@RequestMapping("/api/statistics")
public class StatisticController {//数据统计API接口

    private final HotProductStatisticService hotProductStatisticService;
    private final TransactionStatisticService transactionStatisticService;

    @Autowired
    public StatisticController(HotProductStatisticService hotProductStatisticService,
                               TransactionStatisticService transactionStatisticService) {
        this.hotProductStatisticService = hotProductStatisticService;
        this.transactionStatisticService = transactionStatisticService;
    }

    @Operation(summary = "获取热门商品排行", description = "获取浏览量最高的商品列表")
    @GetMapping("/hot-products")
    public List<Map<String, Object>> getHotProducts(
            @Parameter(description = "返回数量", example = "10")
            @RequestParam(defaultValue = "10") int limit) {
        return hotProductStatisticService.getHotProducts(limit);
    }

    @Operation(summary = "获取用户交易金额排行", description = "获取交易金额最高的用户列表")
    @GetMapping("/user-amount-rank")
    public List<Map<String, Object>> getUserTransactionAmountRank(
            @Parameter(description = "返回数量", example = "10")
            @RequestParam(defaultValue = "10") int limit) {
        return transactionStatisticService.getUserTransactionAmountRank(limit);
    }

    @Operation(summary = "获取用户交易次数排行", description = "获取交易次数最多的用户列表")
    @GetMapping("/user-count-rank")
    public List<Map<String, Object>> getUserTransactionCountRank(
            @Parameter(description = "返回数量", example = "10")
            @RequestParam(defaultValue = "10") int limit) {
        return transactionStatisticService.getUserTransactionCountRank(limit);
    }
}